package com.example.ssmlab2.listener;


import com.mysql.jdbc.AbandonedConnectionCleanupThread;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;


@WebListener
public class DriverListener implements ServletContextListener {
    @Override
    public void contextDestroyed(ServletContextEvent sce){
        Enumeration<Driver> drivers = DriverManager.getDrivers();

        while (drivers.hasMoreElements()){
            Driver driver = drivers.nextElement();

            try {
                DriverManager.deregisterDriver(driver);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
        AbandonedConnectionCleanupThread.checkedShutdown();
    }

}
